package com.hangzhou.xyj.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.model.SingModel;
import com.hangzhou.xyj.ui.widget.views.MyImageView;
import com.hangzhou.xyj.ui.widget.views.MyTextView;

import java.util.List;

/**
 * Created by DT-038 on 2015/12/22.
 * 唱戏推荐曲目
 */
public class RecDramaAdapter extends BaseAdapter {
    private Context mContext;
    private List<SingModel> mDatas;

    public RecDramaAdapter(Context context, List<SingModel> list) {
        this.mContext = context;
        this.mDatas = list;
    }

    @Override
    public int getCount() {
        if (mDatas == null || mDatas.size() == 0) {
            return 0;
        }
        return mDatas.size();
    }

    @Override
    public SingModel getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        RecDramaViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.layout_dian_drama_recommed_item, null);
            viewHolder = new RecDramaViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (RecDramaViewHolder) convertView.getTag();
        }
        viewHolder.setData(mDatas.get(i));
        return convertView;
    }

    class RecDramaViewHolder {
        MyImageView mIvImg;//图片
        MyTextView mTvDramaName;//戏剧名
        MyTextView mTvDrmaAuthor;//戏剧作者

        public RecDramaViewHolder(View convertView) {
            mIvImg = (MyImageView) convertView.findViewById(R.id.miv_image);
            mTvDramaName = (MyTextView) convertView.findViewById(R.id.tv_dian_drama_name);
            mTvDrmaAuthor = (MyTextView) convertView.findViewById(R.id.tv_dian_drama_singer);
        }

        /**
         * 设置数据
         *
         * @param
         * @return
         * @author yaohuix
         * @date 2016/3/11 14:19
         */
        public void setData(SingModel data) {
            mIvImg.displayImage(data.getShowImg());
            mTvDramaName.setText(data.getDramaName());
            mTvDrmaAuthor.setText(data.getRecommendDramaName());
        }
    }
}
